package expressoes;

import java.util.HashMap;

public class Not extends Unaria {

	public Not(Expressao e) {
		super(e);
		operador = "-";
	}

	@Override
	public String getExpressao() {
		
		String retorno = exp.getExpressao();
		
		if(!(exp instanceof Atomica)){
			retorno = "(" + retorno + ")";
		}
		
		retorno = "(" + operador + retorno + ")";
		
		return retorno;
	}

	@Override
	public String calcula(HashMap<String, String> hash) {
		
		String r = exp.calcula(hash);
		
		if(r.equals("0")){
			r = "1";
		} else {
			r = "0";
		}
		
		return r;
	}

	@Override
	public HashMap<String, String> calculaSubExpressoes(
			HashMap<String, String> hash) {
		
		if(!hash.containsKey(exp.getExpressao())){
			hash = exp.calculaSubExpressoes(hash);
		}
		
		hash.put(getExpressao(), hash.get(exp.getExpressao()));
		
		return hash;
	}

}
